﻿using System;
using UnityEngine;

// Token: 0x02000129 RID: 297
public class AnimeLipSync : MonoBehaviour
{
	// Token: 0x170000C0 RID: 192
	// (get) Token: 0x060006B6 RID: 1718 RVA: 0x00027E9C File Offset: 0x0002609C
	// (set) Token: 0x060006B7 RID: 1719 RVA: 0x00027EA4 File Offset: 0x000260A4
	public float RelaxOpen { get; set; }

	// Token: 0x170000C1 RID: 193
	// (get) Token: 0x060006B8 RID: 1720 RVA: 0x00027EB0 File Offset: 0x000260B0
	// (set) Token: 0x060006B9 RID: 1721 RVA: 0x00027EB8 File Offset: 0x000260B8
	public bool Hold { get; set; }

	// Token: 0x060006BA RID: 1722 RVA: 0x00027EC4 File Offset: 0x000260C4
	public void SetAudioSource(AudioSource _src)
	{
		if (this.analyser != null)
		{
			this.analyser.SetAudio(_src);
		}
		this.audio = _src;
	}

	// Token: 0x060006BB RID: 1723 RVA: 0x00027EE4 File Offset: 0x000260E4
	private void Awake()
	{
		this.analyser = new AudioVolumeAnalyzer();
		this.analyser.SetAudio(this.audio);
	}

	// Token: 0x060006BC RID: 1724 RVA: 0x00027F04 File Offset: 0x00026104
	private void Update()
	{
		float num = 0f;
		float num2 = 0f;
		if (!this.Hold)
		{
			num = this.analyser.AnalyzeSound(0.1f);
			num2 = this.analyser.AnalyzeSound(0f);
		}
		float time = num * this.volMul;
		float num3 = this.volToMouth.Evaluate(time);
		float num4 = Mathf.Abs(this.prevVol - num2);
		float value = Mathf.Clamp01(num4 * this.lipSpeed);
		this.animator.SetLayerWeight(this.layerNo, num3);
		this.animator.SetFloat(this.speedName, value);
		float value2 = Mathf.Lerp(0f, this.RelaxOpen, 1f - num3);
		this.animator.SetFloat(this.blendName, value2);
		float value3 = this.analyser.AnalyzeSound(0f);
		if (this.volumeLine)
		{
			this.volumeLine.Add(num);
		}
		if (this.blendLine)
		{
			this.blendLine.Add(num3);
		}
		if (this.rawLine)
		{
			this.rawLine.Add(value3);
		}
		this.prevVol = num2;
	}

	// Token: 0x0400068B RID: 1675
	public AudioSource audio;

	// Token: 0x0400068C RID: 1676
	[SerializeField]
	private Animator animator;

	// Token: 0x0400068D RID: 1677
	[SerializeField]
	private int layerNo;

	// Token: 0x0400068E RID: 1678
	[SerializeField]
	private string blendName = "Blend";

	// Token: 0x0400068F RID: 1679
	[SerializeField]
	private string speedName = "Speed";

	// Token: 0x04000690 RID: 1680
	[SerializeField]
	private float lipSpeed = 1f;

	// Token: 0x04000691 RID: 1681
	private AudioVolumeAnalyzer analyser;

	// Token: 0x04000692 RID: 1682
	private float prevVol;

	// Token: 0x04000693 RID: 1683
	[SerializeField]
	private float volMul = 1f;

	// Token: 0x04000694 RID: 1684
	[SerializeField]
	private AnimationCurve volToMouth;

	// Token: 0x04000695 RID: 1685
	[SerializeField]
	private LogLine volumeLine;

	// Token: 0x04000696 RID: 1686
	[SerializeField]
	private LogLine blendLine;

	// Token: 0x04000697 RID: 1687
	[SerializeField]
	private LogLine rawLine;
}
